/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.msg.template.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.msg.template.entity.ZxMsgTemplate;
import com.jeesite.modules.zx.msg.template.service.ZxMsgTemplateService;

/**
 * 消息模板Controller
 * @author zpp
 * @version 2020-01-17
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/msg/template/zxMsgTemplate")
public class ZxMsgTemplateController extends BaseController {

	@Autowired
	private ZxMsgTemplateService zxMsgTemplateService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZxMsgTemplate get(String id, boolean isNewRecord) {
		return zxMsgTemplateService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZxMsgTemplate zxMsgTemplate, Model model) {
		model.addAttribute("zxMsgTemplate", zxMsgTemplate);
		return "modules/zx/msg/template/zxMsgTemplateList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ZxMsgTemplate> listData(ZxMsgTemplate zxMsgTemplate, HttpServletRequest request, HttpServletResponse response) {
		zxMsgTemplate.setPage(new Page<>(request, response));
		Page<ZxMsgTemplate> page = zxMsgTemplateService.findPage(zxMsgTemplate);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:view")
	@RequestMapping(value = "form")
	public String form(ZxMsgTemplate zxMsgTemplate, Model model) {
		model.addAttribute("zxMsgTemplate", zxMsgTemplate);
		return "modules/zx/msg/template/zxMsgTemplateForm";
	}

	/**
	 * 保存消息模板
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ZxMsgTemplate zxMsgTemplate) {
		zxMsgTemplateService.save(zxMsgTemplate);
		return renderResult(Global.TRUE, text("保存消息模板成功！"));
	}
	
	/**
	 * 停用消息模板
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(ZxMsgTemplate zxMsgTemplate) {
		zxMsgTemplate.setStatus(ZxMsgTemplate.STATUS_DISABLE);
		zxMsgTemplateService.updateStatus(zxMsgTemplate);
		return renderResult(Global.TRUE, text("停用消息模板成功"));
	}
	
	/**
	 * 启用消息模板
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ZxMsgTemplate zxMsgTemplate) {
		zxMsgTemplate.setStatus(ZxMsgTemplate.STATUS_NORMAL);
		zxMsgTemplateService.updateStatus(zxMsgTemplate);
		return renderResult(Global.TRUE, text("启用消息模板成功"));
	}
	
	/**
	 * 删除消息模板
	 */
	@RequiresPermissions("zx:msg:template:zxMsgTemplate:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ZxMsgTemplate zxMsgTemplate) {
		zxMsgTemplateService.delete(zxMsgTemplate);
		return renderResult(Global.TRUE, text("删除消息模板成功！"));
	}
	
}